//strstr()
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <algorithm>
using namespace std;
char str[10000 + 5][20 + 2], key[100000 + 5][20 + 2];
int main()
{
	int p,q,i,j,count;
	cin >> p;
	for (i = 0; i < p; i++)cin >> str[i];
	cin >> q;
	for (i = 0; i < q; i++)cin >> key[i];
	for (i = 0; i < q; i++)
	{
		count = 0;
		for (j = 0; j < p; j++)if (strstr(str[j], key[i]) != NULL)count++;
		cout << count << endl;
	}
	return 0;
}